package com.banzhi.shop.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.banzhi.shop.R;
import com.banzhi.shop.entity.Recommend.recommendInfo_data;
import com.banzhi.shop.utils.ASUtils;
import com.banzhi.shop.utils.NumberUtils;
import com.banzhi.shop.view.CircleImageView;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by LeiHe on 2017/4/26.
 */

public class RecommendAdapter extends BaseAdapter<recommendInfo_data> {

    public RecommendAdapter(Context context, List<recommendInfo_data> data) {
        super(context, data);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final recommendInfo_data data = getData().get(position);
        viewHolder holder = null;
        if (convertView == null) {
            holder = new viewHolder();
            convertView = getInflater().inflate(R.layout.item_recommend, null);
            holder.ivimage = (CircleImageView) convertView.findViewById(R.id.civ_image);
            holder.tvname = (TextView) convertView.findViewById(R.id.tv_name);
            holder.tvmoney = (TextView) convertView.findViewById(R.id.tv_money);
            holder.tvnum = (TextView) convertView.findViewById(R.id.tv_num);
            convertView.setTag(holder);
        }
        holder = (viewHolder) convertView.getTag();
        holder.tvname.setText(data.getNickname());
        holder.tvnum.setText(data.getCountrecommend());
        if(ASUtils.isCanUse(data.getOrderSale())){
            holder.tvmoney.setText(NumberUtils.DecimalFormat(data.getOrderSale()));
        }
        if(ASUtils.isCanUse(data.getAvatar())){
            Picasso.with(getContext()).load(data.getAvatar()).placeholder(R.mipmap.zhanweitu2).into(holder.ivimage);
        }

        return convertView;
    }

    class viewHolder {
        CircleImageView ivimage;
        TextView tvname;
        TextView tvmoney;
        TextView tvnum;
    }

}
